import heapq
import collections
import sortedcontainers
class Solution(object):
    def busiestServers(self, k, arrival, load):
        st = []
        count = collections.defaultdict(int)
        available = sortedcontainers.SortedList([i for i in range(k)])
        for index, time in enumerate(arrival):
            while st and st[0][0] <= time:
                _, node = heapq.heappop(st)
                available.add(node)
            target = index % k
            target_index = available.bisect_left(target)
            if target_index < len(available):
                occupy = available.pop(target_index)
                count[occupy] += 1
                heapq.heappush(st, [time + load[index], occupy])
            else:
                if available:
                    occupy = available.pop(0)
                    count[occupy] += 1
                    heapq.heappush(st, [time + load[index]])
        max_occupy = max(count.values())
        ans = []
        for key in count:
            if count[key] == max_occupy:
                ans.append(key)
        return ans






data = Solution()
k = 3
arrival = [1, 2, 3, 4, 5]
load = [5,2,3,3,3] 
print(data.busiestServers(k, arrival, load))